package com.xmy.cultivate.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.xmy.cultivate.entity.PracticeCheckTeacher;
import com.xmy.cultivate.entity.PracticeCheckTeacher;
import com.xmy.cultivate.service.IPracticeCheckTeacherService;
import com.xmy.cultivate.util.Code;
import com.xmy.cultivate.util.PageResult;
import com.xmy.cultivate.util.Result;
import io.swagger.annotations.ApiImplicitParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.stereotype.Controller;

import java.util.Objects;

/**
 * <p>
 * 审核教师表 前端控制器
 * </p>
 *
 * @author hpiggy
 * @since 2024-10-18
 */
@RestController
@RequestMapping("/api/practiceCheckTeacher")
public class PracticeCheckTeacherController {

    @Autowired
    IPracticeCheckTeacherService iPracticeCheckTeacherService;


    @GetMapping("")
    public Result getPracticeCheckTeacher(@RequestParam(value = "pageNum", defaultValue = "-1") Integer pageNum,
                                          @RequestParam(value = "pageSize", defaultValue = "-1") Integer pageSize) {
        IPage<PracticeCheckTeacher> iPage = new Page<>(pageNum, pageSize);

        QueryWrapper wrapper = new QueryWrapper<>();


        iPracticeCheckTeacherService.page(iPage, wrapper);

        return new Result(Code.OK, new PageResult<>(iPage.getRecords(), iPage.getTotal(), iPage.getPages()));
    }

    @PostMapping("")
    public Result savePracticeCheckTeacher(@RequestBody PracticeCheckTeacher PracticeCheckTeacher) {
        PracticeCheckTeacher eduTask = iPracticeCheckTeacherService.getById(PracticeCheckTeacher.getId());
        if (Objects.isNull(eduTask)) {
            return new Result(Code.EXP_ERROR, null, "该数据不存在");
        }

        iPracticeCheckTeacherService.saveOrUpdate(PracticeCheckTeacher);

        return new Result(Code.SAVE_OK, null, Code.SAVE_OK_MSG);
    }


    @DeleteMapping("")
    @ApiImplicitParam(name = "id", value = "id", required = true, dataType = "String")
    public Result deletePracticeCheckTeacher(@RequestParam(value = "id") String id) {
        PracticeCheckTeacher eduTask = iPracticeCheckTeacherService.getById(id);
        if (Objects.isNull(eduTask)) {
            return new Result(Code.EXP_ERROR, null, "该数据不存在");
        }
        iPracticeCheckTeacherService.removeById(id);
        return new Result(Code.DELETE_OK, null, Code.DELETE_OK_MSG);
    }

}
